package com.exartisan.network;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class FbConnnector {

	private static int timeOut = NetworkUtility.DEFAULT_TIME_OUT;
    private static AsyncHttpClient client = new AsyncHttpClient();
    
    public static void get(String id, String connection, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.setTimeout(timeOut);
    	client.get(getAbsoluteUrl(id, connection), params, responseHandler);
    }

    public static void post(String id, String connection, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.setTimeout(timeOut);
    	client.post(getAbsoluteUrl(id, connection), params, responseHandler);
    }
    
    public static void delete(String id, String connection, AsyncHttpResponseHandler responseHandler) {
        client.setTimeout(timeOut);
    	client.delete(getAbsoluteUrl(id, connection), responseHandler);
    }
    
    public static void cancelRequest(Context c){
    	client.cancelRequests(c, true);
    }

    private static String getAbsoluteUrl(String id, String connection) {
    	if (id!=null)
        return new String(NetworkUtility.GRAPH_API_URL +"/" + id + connection);
    	else
    		return new String(NetworkUtility.GRAPH_API_URL + connection);
    }
    
    public void setTimeOut(int timeOut){
    	FbConnnector.timeOut = timeOut;
    }

}
